package com.young.core.dao.impl;


import com.young.core.dao.BaseDao;
import com.young.core.dao.TriggerDao;
import com.young.core.domain.TriggerDO;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;

@Component
public class TriggerDaoImpl extends BaseDao implements TriggerDao {

    @Override
    public void insert(TriggerDO trigger) {
        this.sqlSession.insert("TriggerMapper.insert", trigger);
    }

    @Override
    public Collection<TriggerDO> getAll(String ip) {
        return this.sqlSession.selectList("TriggerMapper.getAll", ip);
    }

    @Override
    public int update(TriggerDO trigger) {
        return this.sqlSession.update("TriggerMapper.update", trigger);
    }

    @Override
    public void delete(int id) {
        this.delete(Collections.singleton(id));
    }

    @Override
    public void delete(Collection<Integer> ids) {
        if (ids.isEmpty()) {
            return;
        }
        this.sqlSession.delete("TriggerMapper.delete", ids);
    }

    @Override
    public Collection<TriggerDO> getExpired(int ttl) {
        return this.sqlSession.selectList("TriggerMapper.getExpired", ttl);
    }

}
